package com.yq.ylmall.exception;

import com.yq.ylmall.result.ResultCode;
import lombok.Data;

@Data
public class ServiceException extends RuntimeException{
    //异常状态码
    private Integer code;

    ResultCode resultCode;

    /**
     * 通过状态码和错误消息创建异常对象
     * @param message
     * @param code
     */
    public ServiceException(String message, Integer code) {
        super(message);
        this.code = code;
    }

    /**
     * 接收枚举类型对象
     * @param resultCode
     */
    public ServiceException(ResultCode resultCode) {
        super(resultCode.getMessage());
        this.code = resultCode.getCode();
        this.resultCode = resultCode;
    }

    @Override
    public String toString() {
        return "ServiceException{" +
                "code=" + code +
                "} " + super.toString();
    }
}
